using System;
using System.Collections.Generic;
using System.Text;

namespace OgilvyOne.Utility
{
    public class IntUtil
    {
        // Methods
        private IntUtil()
        {
        }

        public static byte ToSafeByte(object value)
        {
            return ToSafeByte(value, 0);
        }

        public static byte ToSafeByte(object value, byte defaultValue)
        {
            byte num = defaultValue;
            if ((value != null) && !value.ToString().Equals(string.Empty))
            {
                try
                {
                    num = Convert.ToByte(value);
                }
                catch
                {
                }
            }
            return num;
        }

        public static decimal ToSafeDecimal(object value)
        {
            return ToSafeDecimal(value, 0M);
        }

        public static decimal ToSafeDecimal(object value, decimal defaultValue)
        {
            decimal num = defaultValue;
            if ((value != null) && !value.ToString().Equals(string.Empty))
            {
                try
                {
                    num = Convert.ToDecimal(value);
                }
                catch
                {
                }
            }
            return num;
        }

        public static int ToSafeInt(object value)
        {
            return ToSafeInt(value, 0);
        }

        public static int ToSafeInt(object value, int defaultValue)
        {
            int num = defaultValue;
            if ((value != null) && !value.ToString().Equals(string.Empty))
            {
                try
                {
                    num = Convert.ToInt32(value);
                }
                catch
                {
                }
            }
            return num;
        }

        public static long ToSafeLong(object value)
        {
            return ToSafeLong(value, 0L);
        }

        public static long ToSafeLong(object value, long defaultValue)
        {
            long num = defaultValue;
            if ((value != null) && !value.ToString().Equals(string.Empty))
            {
                try
                {
                    num = long.Parse(value.ToString());
                }
                catch
                {
                }
            }
            return num;
        }

    }
}
